package com.reluxer;

import com.reluxer.service.SimpleService;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.concurrent.*;

public class Consumer {
    public static void main(String[] args) {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("consumer.xml");
        context.start();
        SimpleService simpleService = (SimpleService) context.getBean("simpleService"); // 获取远程服务代理

        ThreadPoolExecutor executors = new ThreadPoolExecutor(9, 3000,
                0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<Runnable>());
        for (int i = 0; i < 3; i++) {
            executors.execute(() -> {
                for (; ; ) {
                    simpleService.methodA();
                }
            });
            executors.execute(() -> {
                for (; ; ) {
                    simpleService.methodB();
                }
            });
            executors.execute(() -> {
                for (; ; ) {
                    simpleService.methodC();
                }
            });
        }

        try {
            Thread.sleep(Integer.MAX_VALUE);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
